;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var router = require("../hash/pageRouter");
	var validate = require("validate");
	var databind = require("databind");
	var dialog_createFinanceNorm = require("./dialog_createFinanceNorm.html");
	var css_dialog_createFinanceNorm = require("./financeNorm.css");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var dialogCss = require("css_dialog");
	var tools = require("tools");
	var init = function(page) {
		$("#financeNorm-manager").parent().addClass("leftMenu-active");
		
		router.init();
		inquireFinanceFilesNormPageList();
		initEvent();
	};

	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		$("#financeNorm .addFincneNorm").unbind("click").click(function(){
			var ii = layer.open({
        	  area: ['420px', '240px'], //宽高
			  title: "新增融资附件管理",
			  type: 1,
			  skin: 'layui-layer-demo', //样式类名
			  closeBtn: 1, //不显示关闭按钮
			  anim: 2,
			  shadeClose: true, //开启遮罩开启
			  content: dialog_createFinanceNorm,
			  btn: ['确定', '取消'],
			  yes: function(){
			  	databind.submitDom($("#dialog_createFinanceNorm"), function(){
					layer.msg("添加成功");
			  		layer.close(ii);
			  		router.route("financeNorm/financeNorm.html");
				});
			  }
			});
		});
		
	};
	

	//查询列表
	var inquireFinanceFilesNormPageList = function() {
		base.fnAjax({
			action: "inquireFinanceFilesNormPageList.json",
			async: false, //同步异步
			nocode: false, //是否要登陆，true为不用登陆
			oData: {
				pageIndex: pageIndex,
				pageSize: pageSize,
				filesType: 0
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#financeNorm_data_tpl").html();
					var html = juicer(tpl, data);
					$("#financeNorm_tbody").html(html);
					
					//删除
					$("#financeNorm .delete").unbind("click").click(function(){
						var $this = $(this);
						//询问框
						layer.confirm('是否确定删除？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							deleteFinanceFilesNorm($this.parents("tr").attr("normId"));
						}, function(){
							
						});
					});
					
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#financeNorm .pagerCon"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireFinanceFilesNormPageList();
						});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};

	//删除
	var deleteFinanceFilesNorm = function(normId) {
		base.fnAjax({
			action: "deleteFinanceFilesNorm.json?",
			async: false, //同步异步
			oData: {
				normId: normId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					layer.msg("删除成功");
					router.route("financeNorm/financeNorm.html");
				} else {
					base.alert(2, "删除失败");
				}
			}
		});
	};
	
	return {
		init: init
	};
});